unit VENDA;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, Mask, ComCtrls;

type
  TForm1 = class(TForm)
    GroupBox1: TGroupBox;
    Label2: TLabel;
    Button5: TButton;
    mskCupons: TMaskEdit;
    GroupBox2: TGroupBox;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    RadioButton3: TRadioButton;
    RadioButton4: TRadioButton;
    GroupBox3: TGroupBox;
    Button1: TButton;
    Button2: TButton;
    memo1: TRichEdit;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button5Click(Sender: TObject);
    procedure RadioButton1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure mskCuponsKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  com,a:integer;
  Resp:String;
  Retorno:Integer;
  Comando: array[0..512] of Char;
  Status:array[0..512] of Char;
  Extensao:LongInt;
  function ECFOpen(numero:longint;tempo:longint;log:longint;mostra:longint):integer; stdcall;
  external 'SWECF.DLL' index 1;
  procedure ECFClose; stdcall;
  external 'SWECF.DLL' index 2;
  function ECFWrite(Comando:PChar):longint; stdcall;
  external 'SWECF.DLL' index 3;
  Function ECFRead(Status:PChar;Extensao:longint):Longint;stdcall;
  external 'SWECF.DLL' index 4;

implementation

{$R *.DFM}


procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
     EcfClose;
end;

procedure TForm1.Button5Click(Sender: TObject);
var i:integer;
begin

  for i := 1 to Trunc(StrToFloat(mskCupons.text)) do
    begin
     GroupBox1.caption := FloatToStr(i);
     memo1.lines.add('');
     Application.processmessages;
     Comando:=#27+'.17                    }';
     Retorno:=ECFWrite(Comando);
     ECFRead(Status,512);
     memo1.lines.add(status);
     if (status = '.-P006}') or (status = '.-P002') then break;

     Application.processmessages;

     Comando:=#27+'.011            0001000000000100000000000100PRODUTO 1               I  }';

     Retorno:=ECFWrite(Comando);
     ECFRead(Status,512);
     memo1.lines.add(status);
     if (status = '.-P006}') or (status = '.-P002') then break;

     Application.processmessages;
     Comando:=#27+'.1001000000000100}';
     Retorno:=ECFWrite(Comando);
     ECFRead(Status,512);
     memo1.lines.add(status);
     if (status = '.-P006}') or (status = '.-P002') then break;


     Application.processmessages;
     Comando:=#27+'.12}';
     Retorno:=ECFWrite(Comando);
     ECFRead(Status,512);
     memo1.lines.add(status);
     if (status = '.-P006}') or (status = '.-P002') then break;
  end;
end;

procedure TForm1.RadioButton1Click(Sender: TObject);
begin
  ecfclose;
  if RadioButton1.checked then
    begin
     ECFOpen(1,20,0,0);
    end;

  if RadioButton2.checked then
    begin
      ECFOpen(2,20,0,0);
    end;

  if RadioButton3.checked then
    begin
      ECFOpen(3,20,0,0);
    end;

  if RadioButton4.checked then
    begin
      ECFOpen(4,20,0,0);
    end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ECFOpen(1,10,1,0);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Comando := #27+'.05}';
  EcfWrite(Comando);
  ECFRead(status,512);
  memo1.lines.add('');
  memo1.lines.add(status);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Comando := #27+'.13N}';
  EcfWrite(Comando);
  ECFRead(status,512);
  Memo1.lines.add('');
  memo1.lines.add(status);
end;

procedure TForm1.mskCuponsKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key = VK_RETURN THEN  button5.setfocus;
end;

end.
